package cn.stylefeng.guns.modular.storage.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.storage.entity.StorageAllocationOutDetailed;
import cn.stylefeng.guns.modular.storage.mapper.StorageAllocationOutDetailedMapper;
import cn.stylefeng.guns.modular.storage.model.params.StorageAllocationOutDetailedParam;
import cn.stylefeng.guns.modular.storage.model.result.StorageAllocationOutDetailedResult;
import  cn.stylefeng.guns.modular.storage.service.StorageAllocationOutDetailedService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 调拨出库明细表 服务实现类
 * </p>
 *
 * @author zhucx
 * @since 2021-12-02
 */
@Service
public class StorageAllocationOutDetailedServiceImpl extends ServiceImpl<StorageAllocationOutDetailedMapper, StorageAllocationOutDetailed> implements StorageAllocationOutDetailedService {

    @Override
    public void add(StorageAllocationOutDetailedParam param){
        StorageAllocationOutDetailed entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(StorageAllocationOutDetailedParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(StorageAllocationOutDetailedParam param){
        StorageAllocationOutDetailed oldEntity = getOldEntity(param);
        StorageAllocationOutDetailed newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public StorageAllocationOutDetailedResult findBySpec(StorageAllocationOutDetailedParam param){
        return null;
    }

    @Override
    public List<StorageAllocationOutDetailedResult> findListBySpec(StorageAllocationOutDetailedParam param){
        return this.baseMapper.findListBySpec(param);
    }

    @Override
    public LayuiPageInfo findPageBySpec(StorageAllocationOutDetailedParam param,String condition){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param,condition);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(StorageAllocationOutDetailedParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private StorageAllocationOutDetailed getOldEntity(StorageAllocationOutDetailedParam param) {
        return this.getById(getKey(param));
    }

    private StorageAllocationOutDetailed getEntity(StorageAllocationOutDetailedParam param) {
        StorageAllocationOutDetailed entity = new StorageAllocationOutDetailed();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
